import {Injectable} from '@angular/core';
import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {MyStorageService} from './my.storage.service';
import {RequestService} from './request.service';
import packageJson from '../../package.json';
import {Response} from './response';

@Injectable({
  providedIn: 'root'
})
export class ConstantsService {

  constructor(private message: NzMessageService, private storage: MyStorageService,
              private request: RequestService, private modalService: NzModalService) {
  }

  /**
   * 简单提示信息
   */
  auto(res: Response, time?: number) {
    if (res.isSuccess) {
      this.message.success(res.msg, {nzDuration: time || 3000});
    } else {
      this.message.error(res.msg, {nzDuration: time || 3000});
    }
  }

  /**
   * 简单提示信息
   */
  success(msg) {
    this.message.success(msg);
  }

  /**
   * 提示信息
   */
  successModal(msg) {
    this.modalService.success({
      nzTitle: msg.title,
      nzContent: msg.content
    });
  }

  /**
   * 简单提示信息
   */
  error(msg) {
    this.message.error(msg);
  }

  /**
   * 简单提示信息
   */
  info(msg) {
    this.message.info(msg);
  }

  /**
   * 简单提示信息
   */
  warning(msg) {
    this.message.warning(msg);
  }

  /**
   * loading
   * @param msg 消息
   */
  loading(msg): string {
    return this.message.loading(msg, {nzDuration: 0}).messageId;
  }

  /**
   * 删除消息
   * @param index 消息id
   */
  removeMsg(index)  {
    this.message.remove(index);
  }

  getProjectTitle() {
    return packageJson.description + packageJson.version;
  }
}
